﻿#region Using Directives
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.ComponentModel.Design;
using NetROS.Tiers.Entities;
using NetROS.Tiers.Data;
using NetROS.Tiers.Data.Bases;
using NetROS.Tiers.Services;
#endregion

namespace NetROS.Tiers.Web.Data
{
	/// <summary>
	/// Represents the DataRepository.VwObracunKamataTraziProvider object that provides
	/// data to data-bound controls in multi-tier Web application architectures.
	/// </summary>
	[CLSCompliant(true)]
	[Designer(typeof(VwObracunKamataTraziDataSourceDesigner))]
	public class VwObracunKamataTraziDataSource : ReadOnlyDataSource<VwObracunKamataTrazi>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the VwObracunKamataTraziDataSource class.
		/// </summary>
		public VwObracunKamataTraziDataSource() : base(new VwObracunKamataTraziService())
		{
		}

		#endregion Constructors
		
		#region Properties
		
		/// <summary>
		/// Gets a reference to the VwObracunKamataTraziDataSourceView used by the VwObracunKamataTraziDataSource.
		/// </summary>
		protected VwObracunKamataTraziDataSourceView VwObracunKamataTraziView
		{
			get { return ( View as VwObracunKamataTraziDataSourceView ); }
		}
		
		/// <summary>
		/// Gets or sets the name of the method or function that
		/// the VwObracunKamataTraziDataSource control invokes to retrieve data.
		/// </summary>
		public new VwObracunKamataTraziSelectMethod SelectMethod
		{
			get
			{
				VwObracunKamataTraziSelectMethod selectMethod = VwObracunKamataTraziSelectMethod.GetAll;
				Object method = ViewState["SelectMethod"];
				if ( method != null )
				{
					selectMethod = (VwObracunKamataTraziSelectMethod) method;
				}
				return selectMethod;
			}
			set { ViewState["SelectMethod"] = value; }
		}
		
		#endregion Properties
		
		#region Methods

		/// <summary>
		/// Creates a new instance of the VwObracunKamataTraziDataSourceView class that is to be
		/// used by the VwObracunKamataTraziDataSource.
		/// </summary>
		/// <returns>An instance of the VwObracunKamataTraziDataSourceView class.</returns>
		protected override BaseDataSourceView<VwObracunKamataTrazi, Object> GetNewDataSourceView()
		{
			return new VwObracunKamataTraziDataSourceView(this, DefaultViewName);
		}
		
		/// <summary>
        /// Creates a cache hashing key based on the startIndex, pageSize and the SelectMethod being used.
        /// </summary>
        /// <param name="startIndex">The current start row index.</param>
        /// <param name="pageSize">The current page size.</param>
        /// <returns>A string that can be used as a key for caching purposes.</returns>
		protected override string CacheHashKey(int startIndex, int pageSize)
        {
			return String.Format("{0}:{1}:{2}", SelectMethod, startIndex, pageSize);
        }
		
		#endregion Methods
	}
	
	/// <summary>
	/// Supports the VwObracunKamataTraziDataSource control and provides an interface for
	/// data-bound controls to perform data operations with business and data objects.
	/// </summary>
	public class VwObracunKamataTraziDataSourceView : ReadOnlyDataSourceView<VwObracunKamataTrazi>
	{
		#region Declarations

		#endregion Declarations
		
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the VwObracunKamataTraziDataSourceView class.
		/// </summary>
		/// <param name="owner">A reference to the VwObracunKamataTraziDataSource which created this instance.</param>
		/// <param name="viewName">The name of the view.</param>
		public VwObracunKamataTraziDataSourceView(VwObracunKamataTraziDataSource owner, String viewName)
			: base(owner, viewName)
		{
		}
		
		#endregion Constructors
		
		#region Properties

		/// <summary>
		/// Gets a strongly-typed reference to the Owner property.
		/// </summary>
		internal VwObracunKamataTraziDataSource VwObracunKamataTraziOwner
		{
			get { return Owner as VwObracunKamataTraziDataSource; }
		}

		/// <summary>
		/// Gets or sets the name of the method or function that
		/// the DataSource control invokes to retrieve data.
		/// </summary>
		internal new VwObracunKamataTraziSelectMethod SelectMethod
		{
			get { return VwObracunKamataTraziOwner.SelectMethod; }
			set { VwObracunKamataTraziOwner.SelectMethod = value; }
		}

		/// <summary>
		/// Gets a strongly typed reference to the Provider property.
		/// </summary>
		internal VwObracunKamataTraziService VwObracunKamataTraziProvider
		{
			get { return Provider as VwObracunKamataTraziService; }
		}

		#endregion Properties
		
		#region Methods
		
		/// <summary>
		/// Gets a collection of Entity objects based on the value of the SelectMethod property.
		/// </summary>
		/// <param name="count">The total number of rows in the DataSource.</param>
		/// <returns>A collection of Entity objects.</returns>
		protected override IList<VwObracunKamataTrazi> GetSelectData(out int count)
		{
			Hashtable values = CollectionsUtil.CreateCaseInsensitiveHashtable(GetParameterValues());
			IList<VwObracunKamataTrazi> results = null;
			// VwObracunKamataTrazi item;
			count = 0;
			
			System.String sp88_Konto;			System.Int32? sp88_IDKlijent;			System.DateTime? sp88_DatumObracuna;			System.Int32? sp88_MT;			System.String sp89_Konto;			System.Int32? sp89_IDKlijent;			System.DateTime? sp89_DatumObracuna;			System.Int32? sp89_MT;
			switch ( SelectMethod )
			{
				case VwObracunKamataTraziSelectMethod.Get:
					results = VwObracunKamataTraziProvider.Get(WhereClause, OrderBy, PageIndex, PageSize, out count);
                    break;
				case VwObracunKamataTraziSelectMethod.GetPaged:
					results = VwObracunKamataTraziProvider.GetPaged(WhereClause, OrderBy, PageIndex, PageSize, out count);
					break;
				case VwObracunKamataTraziSelectMethod.GetAll:
					results = VwObracunKamataTraziProvider.GetAll(StartIndex, PageSize, out count);
                    break;
				case VwObracunKamataTraziSelectMethod.Find:
					results = VwObracunKamataTraziProvider.Find(FilterParameters, OrderBy, StartIndex, PageSize, out count);
                    break;
				// Custom
				case VwObracunKamataTraziSelectMethod.PrebaciUObracunVratiVw:
					sp88_Konto = (System.String) EntityUtil.ChangeType(values["@Konto"], typeof(System.String));
					sp88_IDKlijent = (System.Int32?) EntityUtil.ChangeType(values["@IDKlijent"], typeof(System.Int32?));
					sp88_DatumObracuna = (System.DateTime?) EntityUtil.ChangeType(values["@DatumObracuna"], typeof(System.DateTime?));
					sp88_MT = (System.Int32?) EntityUtil.ChangeType(values["@MT"], typeof(System.Int32?));
					results = VwObracunKamataTraziProvider.PrebaciUObracunVratiVw(sp88_Konto, sp88_IDKlijent, sp88_DatumObracuna, sp88_MT, StartIndex, PageSize);
					break;
				case VwObracunKamataTraziSelectMethod.PrebaciUObracunVratiVw_old:
					sp89_Konto = (System.String) EntityUtil.ChangeType(values["@Konto"], typeof(System.String));
					sp89_IDKlijent = (System.Int32?) EntityUtil.ChangeType(values["@IDKlijent"], typeof(System.Int32?));
					sp89_DatumObracuna = (System.DateTime?) EntityUtil.ChangeType(values["@DatumObracuna"], typeof(System.DateTime?));
					sp89_MT = (System.Int32?) EntityUtil.ChangeType(values["@MT"], typeof(System.Int32?));
					results = VwObracunKamataTraziProvider.PrebaciUObracunVratiVw_old(sp89_Konto, sp89_IDKlijent, sp89_DatumObracuna, sp89_MT, StartIndex, PageSize);
					break;
				default:
					break;
			}

			if ( results != null && count < 1 )
			{
				count = results.Count;
			}
			
			return results;
		}
		
		#endregion Methods
	}

	#region VwObracunKamataTraziSelectMethod
	
	/// <summary>
	/// Enumeration of method names available for the VwObracunKamataTraziDataSource.SelectMethod property.
	/// </summary>
	public enum VwObracunKamataTraziSelectMethod
	{
		/// <summary>
		/// Represents the Get method.
		/// </summary>
		Get,
		/// <summary>
		/// Represents the GetPaged method.
		/// </summary>
		GetPaged,
		/// <summary>
		/// Represents the GetAll method.
		/// </summary>
		GetAll,
		/// <summary>
		/// Represents the Find method.
		/// </summary>
		Find,
		/// <summary>
		/// Represents the PrebaciUObracunVratiVw method.
		/// </summary>
		PrebaciUObracunVratiVw,
		/// <summary>
		/// Represents the PrebaciUObracunVratiVw_old method.
		/// </summary>
		PrebaciUObracunVratiVw_old
	}
	
	#endregion VwObracunKamataTraziSelectMethod
	
	#region VwObracunKamataTraziDataSourceDesigner

	/// <summary>
	/// Provides design-time support in a design host for the VwObracunKamataTraziDataSource class.
	/// </summary>
	public class VwObracunKamataTraziDataSourceDesigner : ReadOnlyDataSourceDesigner<VwObracunKamataTrazi>
	{
		/// <summary>
		/// Initializes a new instance of the VwObracunKamataTraziDataSourceDesigner class.
		/// </summary>
		public VwObracunKamataTraziDataSourceDesigner()
		{
		}

		/// <summary>
		/// Gets or sets the SelectMethod property.
		/// </summary>
		public new VwObracunKamataTraziSelectMethod SelectMethod
		{
			get { return ((VwObracunKamataTraziDataSource) DataSource).SelectMethod; }
			set { SetPropertyValue("SelectMethod", value); }
		}

		/// <summary>Gets the designer action list collection for this designer.</summary>
		/// <returns>The <see cref="T:System.ComponentModel.Design.DesignerActionListCollection"/>
		/// associated with this designer.</returns>
		public override DesignerActionListCollection ActionLists
		{
			get
			{
				DesignerActionListCollection actions = new DesignerActionListCollection();
				actions.Add(new VwObracunKamataTraziDataSourceActionList(this));
				actions.AddRange(base.ActionLists);
				return actions;
			}
		}
	}

	#region VwObracunKamataTraziDataSourceActionList

	/// <summary>
	/// Supports the VwObracunKamataTraziDataSourceDesigner class.
	/// </summary>
	internal class VwObracunKamataTraziDataSourceActionList : DesignerActionList
	{
		private VwObracunKamataTraziDataSourceDesigner _designer;

		/// <summary>
		/// Initializes a new instance of the VwObracunKamataTraziDataSourceActionList class.
		/// </summary>
		/// <param name="designer"></param>
		public VwObracunKamataTraziDataSourceActionList(VwObracunKamataTraziDataSourceDesigner designer) : base(designer.Component)
		{
			_designer = designer;
		}

		/// <summary>
		/// Gets or sets the SelectMethod property.
		/// </summary>
		public VwObracunKamataTraziSelectMethod SelectMethod
		{
			get { return _designer.SelectMethod; }
			set { _designer.SelectMethod = value; }
		}

		/// <summary>
		/// Returns the collection of <see cref="T:System.ComponentModel.Design.DesignerActionItem"/>
		/// objects contained in the list.
		/// </summary>
		/// <returns>A <see cref="T:System.ComponentModel.Design.DesignerActionItem"/>
		/// array that contains the items in this list.</returns>
		public override DesignerActionItemCollection GetSortedActionItems()
		{
			DesignerActionItemCollection items = new DesignerActionItemCollection();
			items.Add(new DesignerActionPropertyItem("SelectMethod", "Select Method", "Methods"));
			return items;
		}
	}

	#endregion VwObracunKamataTraziDataSourceActionList

	#endregion VwObracunKamataTraziDataSourceDesigner

	#region VwObracunKamataTraziFilter

	/// <summary>
	/// A strongly-typed instance of the <see cref="SqlFilter&lt;EntityColumn&gt;"/> class
	/// that is used exclusively with a <see cref="VwObracunKamataTrazi"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class VwObracunKamataTraziFilter : SqlFilter<VwObracunKamataTraziColumn>
	{
	}

	#endregion VwObracunKamataTraziFilter

	#region VwObracunKamataTraziExpressionBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="SqlExpressionBuilder&lt;EntityColumn&gt;"/> class
	/// that is used exclusively with a <see cref="VwObracunKamataTrazi"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class VwObracunKamataTraziExpressionBuilder : SqlExpressionBuilder<VwObracunKamataTraziColumn>
	{
	}
	
	#endregion VwObracunKamataTraziExpressionBuilder		
}

